package com.macro.mall.portal.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.portal.domain.GuidancePrice;
import com.macro.mall.portal.domain.Transfer;
import com.macro.mall.portal.service.IGuidancePriceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/guidance")
@Api(tags = "GuidancePriceController", description = "指导价")
public class GuidancePriceController {

    @Autowired
    private IGuidancePriceService guidancePriceService;

    private static Map localCacheStore = new HashMap();

    static {
        localCacheStore.put("person", 2678987);
    }

    @ApiOperation("查询项目名称")
    @RequestMapping(value = "/selectList", method = RequestMethod.POST)
    public CommonResult selectList(@RequestBody GuidancePrice guidancePrice) {

        List<GuidancePrice> guidancePriceList = null;
        try {
            guidancePriceList = guidancePriceService.priceList(guidancePrice);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed("服务器异常");
        }
        return CommonResult.success(guidancePriceList);
    }

    @ApiOperation("查询详情")
    @RequestMapping(value = "/selectOne", method = RequestMethod.POST)
    public CommonResult selectOne(@RequestBody GuidancePrice guidancePrice) {
//        Map<String, List<GuidancePrice>> guidancePriceList = null;
        GuidancePrice guidancePriceList = null;
        try {
            guidancePriceList = guidancePriceService.selectList(guidancePrice);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed("服务器异常");
        }
        return CommonResult.success(guidancePriceList);
    }

    @ApiOperation("查询人数")
    @RequestMapping(value = "/selectPerson", method = RequestMethod.POST)
    public CommonResult selectPerson() {

        try {
            int max = 3, min = 1;
            long randomNum = System.currentTimeMillis();
            int ran3 = (int) (randomNum % (max - min) + min);
            localCacheStore.put("person", (int) localCacheStore.get("person") + ran3);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed("服务器异常");
        }
        return CommonResult.success(localCacheStore);
    }
}
